import 'package:badges/badges.dart';
import 'package:flutter/material.dart';

import '../../../common/style.dart';
import '../../../config/global_config.dart';
import '../../../utils/screenutil/fit.dart';

class Info extends StatelessWidget {
  int elevatorsCount;
  int messagesCount;
  Function callback;

  /// 信息暂时模块
  /// * [elevatorsCount] int|管理的电梯数量|选填
  /// * [messagesCount] int|未读消息数量|选填
  /// * [callback] Function|回调函数|选填
  Info({int elevatorsCount, int messagesCount, Function callback})
      : this.elevatorsCount = elevatorsCount != null ? elevatorsCount : 0,
        this.messagesCount = messagesCount != null ? messagesCount : 0,
        this.callback = callback;

  @override
  Widget build(BuildContext context) {
    return Container(
      width: 580.f,
      height: 164.f,
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(20.f),
      ),
      margin: EdgeInsets.only(bottom: 28.f),
      child: Flex(
        direction: Axis.horizontal,
        children: [
          Expanded(
            child: Container(
              padding: EdgeInsets.only(left: 30.f),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    "我的电梯管理",
                    style: TextStyle(
                      color: GlobalConfig.titleContent,
                    ),
                  ),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.start,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      Text(
                        "$elevatorsCount",
                        style: TextStyle(
                          color: Colors.amberAccent,
                          fontSize: 40.f,
                        ),
                      ),
                      Text(
                        " 台",
                        style: TextStyle(
                          color: GlobalConfig.titleContent,
                        ),
                      ),
                    ],
                  )
                ],
              ),
            ),
          ),
          SizedBox(
            width: 1.f,
            child: Container(
              height: 128.f,
              decoration: BoxDecoration(
                color: GlobalConfig.borderColor,
                gradient: Style.gradient,
              ),
            ),
          ),
          Expanded(
            child: InkWell(
              onTap: () => callback(),
              child: Container(
                padding: EdgeInsets.only(left: 30.f),
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    messagesCount > 0
                        ? Badge(
                            position: BadgePosition.topStart(
                              start: 50.f,
                              top: 1.f,
                            ),
                            padding: EdgeInsets.all(5.f),
                            badgeContent: null,
                            child: Text(
                              "消息",
                              style: TextStyle(
                                color: GlobalConfig.titleContent,
                              ),
                            ),
                          )
                        : Text(
                            "消息",
                            style: TextStyle(
                              color: GlobalConfig.titleContent,
                            ),
                          ),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.start,
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        Text(
                          "$messagesCount",
                          style: TextStyle(
                            color: Colors.amberAccent,
                            fontSize: 40.f,
                          ),
                        ),
                        Text(
                          " 项",
                          style: TextStyle(
                            color: GlobalConfig.titleContent,
                          ),
                        ),
                        Text(
                          " 去处理 >",
                          style: TextStyle(
                            color: Colors.amberAccent,
                          ),
                        ),
                      ],
                    )
                  ],
                ),
              ),
            ),
          )
        ],
      ),
    );
  }
}
